﻿using System;

using log4net;


namespace ExtensibleEventViewer.Console.Presenters
{
	/// <summary>
	/// Base class for all presenters
	/// </summary>
	/// <typeparam name="TViewType">View type</typeparam>
	internal abstract class PresenterBase<TViewType>
	{
		private readonly ILog _log;

		private readonly TViewType _view;

		/// <summary>
		/// Initializes presenter
		/// </summary>
		/// <param name="view">Viewinstance</param>
		protected PresenterBase(TViewType view)
		{
			_view = view;

			_log = LogManager.GetLogger(GetType());
		}

		/// <summary>
		/// View instance
		/// </summary>
		protected TViewType View
		{
			get
			{
				return _view;
			}
		}

		protected void HandleException(Exception ex)
		{
			try
			{
				_log.Error("DomainUnhandledException", ex.GetBaseException());
			}
			catch
			{ }
		}
	}
}
